Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-package] remove unnecessary allocations in ctypes code #6111

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

jameslamb
Copy link
Collaborator

A few places in the Python package use a pattern like the following:

ctypes.c_char_p(*[ctypes.addressof(string_buffer)])

That's identical to the following ...

ctypes.c_char_p(ctypes.addressof(string_buffer))

... except that it involves allocating, unpacking, and then immediately freeing a list object.

This PR proposes removing those unnecessary allocations, to make those code paths slightly faster and reduce their memory usage a tiny bit.

Notes for reviewers

Docs on ctypes.c_char_p() accepting a memory address as an int: https://docs.python.org/3/library/ctypes.html#ctypes.c_char_p

@jameslamb jameslamb merged commit 60a4a13 into master Sep 25, 2023
41 checks passed
@jameslamb jameslamb deleted the unnecessary-lists branch September 25, 2023 15:50
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants